import { loadEnv, defineConfig } from "vite";
import testConfig from "./vite.test.config";
import baseConfig from "./vite.base.config";
import prodConfig from "./vite.prod.config";
import devConfig from "./vite.dev.config";

/**
 *@description serve 环境的mode
 */
const serveModeEnvResolver = {
  development: () => ({ ...baseConfig, ...devConfig }),
  test: () => ({ ...baseConfig, ...testConfig }),
};

/**
 *@description 生产环境的mode
 */
const buileModeEnvResolver = {
  production: () => ({ ...baseConfig, ...prodConfig }),
};

/**
 *@description build/serve 环境
 */
const commandResolver = {
  build: (mode = "production") => {
   return buileModeEnvResolver[mode]();
  },
  serve: (mode = "development") => {
    return serveModeEnvResolver[mode]();
  },
};

export default defineConfig(({ command, mode }) => {
  const env = loadEnv(mode, process.cwd(), "");
  // console.log(commandResolver[command](mode))
  return commandResolver[command](mode);
});
